package cn.com.controller.manageController;

import cn.com.Enum.UserAuth;
import cn.com.annotation.Auth;
import cn.com.constant.Code;
import cn.com.db.model.Store;
import cn.com.db.service.*;
import cn.com.util.DataResult;
import cn.com.util.JsonUtil;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Auth(UserAuth.ADMIN)
@RequestMapping("/back/manage")
@RestController
public class ManageController {

	@Autowired
	OrderService orderService;
	@Autowired
	GoodsService goodsService;
	@Autowired
	SellerService sellerService;
	@Autowired
	StoreService storeService;
	@Autowired
	UserService userService;
	@Autowired
	DiyOrderService diyOrderService;

	@RequestMapping(value = "getTurnover", method = RequestMethod.GET)
	public String getTurnover() {
		DataResult dataResult = new DataResult();
		BigDecimal result = new BigDecimal("0.00");
		BigDecimal result1 = orderService.getTurnover(null, null);
		if(result1 != null){
			result = result.add(result1);
		}
		BigDecimal result2 = diyOrderService.getTurnover(null, null);
		if(result2 != null){
			result = result.add(result2);
		}
		dataResult.setData(result);
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}
	
	

	@RequestMapping(value = "getTodayTurnover", method = RequestMethod.GET)
	public String getTodayTurnover() {
		DataResult dataResult = new DataResult();
		BigDecimal result = new BigDecimal("0.00");
		BigDecimal result1 = orderService.getTodayTurnover(null, null);
		if(result1 != null){
			result = result.add(result1);
		}
		BigDecimal result2 = diyOrderService.getTodayTurnover(null, null);
		if(result2 != null){
			result = result.add(result2);
		}
		dataResult.setData(result);
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getDealPeopleNum", method = RequestMethod.GET)
	public String getDealPeopleNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(orderService.getDealPeopleNum(null, null) + diyOrderService.getDealPeopleNum(null, null));
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getOrderNum", method = RequestMethod.GET)
	public String getOrderNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(orderService.getOrderNum(null, null) + diyOrderService.getDiyOrderNum(null, null));
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getSellerNum", method = RequestMethod.GET)
	public String getSellerNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(sellerService.getSellerNum());
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getBuyerNum", method = RequestMethod.GET)
	public String getBuyerNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(userService.getUserNum());
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getStoreNum", method = RequestMethod.GET)
	public String getStoreNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(storeService.countStore(new Store()));
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getGoodsNum", method = RequestMethod.GET)
	public String getGoodsNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(goodsService.getGoodsNum());
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

}
